package com.eh.iteratorAndComposition.base;

import java.util.Iterator;

/**
 * Created by David on 2016/5/1.
 */
public abstract class AbstractMenu implements MenuComponent {
    protected String name;
    protected String description;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public double getPrice() {
        throw new UnsupportedOperationException();
    }

    public boolean isVegetarian() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void print() {
        printMenu();
        Iterator<MenuComponent> iterator = iterator();
        while (iterator.hasNext()) {
            MenuComponent menuComponent = iterator.next();
            menuComponent.print();
        }
    }

    public void printMenu() {
        System.out.printf("%s%n---------%s%n", getName(), getDescription());
    }

    @Override
    public Iterator<MenuComponent> iterator() {
        return createIterator();
    }

    protected abstract Iterator<MenuComponent> createIterator();
}
